package com.org.javabody.Split;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SplitDemo {

	public String[] mySplit(String str, String splitStr) {
		String[] s = str.split(splitStr);
		return s;
	}

	public static void main(String[] args) {
		SplitDemo sp = new SplitDemo();
		String str = "a|b|c";
		String[] arraylist =sp.mySplit(str, "\\|");
		System.out.println("①数组无法直接输出:"+arraylist);//数组无法直接输出的

		System.out.print("②用遍历循环输出:");
		for(int i=0; i < arraylist.length; i++) {
			if(i < arraylist.length-1) {
				System.out.print(arraylist[i]+";");
			} else if(i == (arraylist.length-1)){
				System.out.print(arraylist[i]);
			}	
		}
		System.out.println("");
		System.out.print("③转化成list输出:");
		List list = new ArrayList();
		for(int i=0; i < arraylist.length; i++) {
			list.add(arraylist[i]);
		}
		System.out.println(list);
		
		HashMap map = new HashMap();
		for(int i=0; i < arraylist.length; i++) {
			map.put(i, arraylist[i]);
		}
		System.out.print("④转化成map输出:");
		System.out.println(map);
		System.out.println("⑤转化成map取主键值和键值输出(map常用用法):");
		Set set = map.entrySet();
		Iterator iter = set.iterator();
		while(iter.hasNext()) {
			Map.Entry entry = (Map.Entry)iter.next();
			Object key = entry.getKey();
			Object value = entry.getValue();
			System.out.println("主键"+key+":键值"+value);   //散列随机的

		}
	}
}
